package cn.melonlib.cores.graphql.model.bean;

import cn.hutool.core.util.IdUtil;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
public class GraphQLConnection<ENTITY> implements GraphQLQueryResult<List<GraphQLEdge<ENTITY>>>{

    private String uuid= IdUtil.fastSimpleUUID();

    private List<GraphQLEdge<ENTITY>> edges;

    private GraphQLResultInfo resultInfo;

    private GraphQLPageInfo pageInfo;

    private Long totalCount;

    public GraphQLConnection() {
    }

    public GraphQLConnection(List<ENTITY> edges, GraphQLPageInfo pageInfo, GraphQLResultInfo resultInfo) {
        this.edges = edges.stream().map(GraphQLEdge::new).collect(Collectors.toList());
        this.pageInfo = pageInfo;
        this.resultInfo=resultInfo;
        this.totalCount=resultInfo.getTotalCount();
    }
}
